package com.lanchetech.user.controller;

import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.CoinOrderResp;
import com.lanchetech.bean.response.CoinProductResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.CoinProductVO;
import com.lanchetech.entity.CoinOrder;
import com.lanchetech.entity.User;
import com.lanchetech.user.service.CoinService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@Api(value = "积分商城接口", tags = "积分商城")
@RequestMapping("/api/coin")
@RestController
public class CoinController {

    @Autowired
    CoinService coinService;

    @ApiOperation("获取积分商城商品分页")
    @PostMapping("/getCoinProductPage")
    public ResultData<BasePageResp<CoinProductResp>> getCoinProductPage(@RequestBody PageReq req) {
        return coinService.getCoinProductPage(req);
    }

    @ApiOperation("获取积分商城商品详情")
    @GetMapping("/getCoinProductDetail")
    public ResultData<CoinProductVO> getCoinProductDetail(@AuthenticationPrincipal User user, @RequestParam("id") Long id) {
        return coinService.getCoinProductDetail(user, id);
    }


    @ApiOperation(value = "兑换/抽奖积分商品")
    @PostMapping("/createCoinOrder")
    public ResultData<Boolean> createCoinOrder(@AuthenticationPrincipal User user, @RequestBody CoinOrder coinOrder) {
        return coinService.createCoinOrder(user, coinOrder);
    }


    @ApiOperation("获取积分商品订单分页")
    @PostMapping("/getCoinOrderPage")
    public ResultData<BasePageResp<CoinOrderResp>> getCoinOrderPage(@AuthenticationPrincipal User user, @RequestBody PageReq req) {
        return coinService.getCoinOrderPage(user, req);
    }

    @ApiOperation("获取积分商品订单详情")
    @GetMapping("/getCoinOrderDetail")
    public ResultData<CoinOrderResp> getCoinOrderDetail(@RequestParam("id") Long id) {
        return coinService.getCoinOrderDetail(id);
    }

}
